package first.niuke.midding;

import java.util.Stack;

/**
 * @ClassName NC1
 * @description:
 * @author: 荣燊
 * @create: 2021-07-19 10:23
 **/
public class NC1 {
    // 大数加法，栈

    public String solve (String s, String t) {
        // write code here
        Stack<Integer> stack = new Stack<>();
        char[] s1 = s.toCharArray();
        char[] t1 = t.toCharArray();
        int flag = 0;
        int i = s1.length-1;
        int j = t1.length-1;

        while (i >= 0 || j >= 0 || flag != 0) {
//             if (i >= 0) {
//                 flag = (s1[i]-'0') + flag;
//                 i--;
//             } else {
//                 flag = flag + 0;
//             }
            flag += i>=0 ? (s1[i--]-'0') : 0;
            flag += j>=0 ? (t1[j--]-'0') : 0;
//             if (j >= 0) {
//                 flag = (t1[j]-'0') + flag;
//                 j--;
//             } else {
//                 flag = flag + 0;
//             }
            stack.push(flag%10);
            flag /= 10;
        }

        StringBuilder str = new StringBuilder();
        while (!stack.isEmpty()) {
            str.append(stack.pop());
        }
        return str.toString();

    }
}
